

<template>
  <div class="home">
      <MyHead title="首页" :noBack="true" ></MyHead>
      <div class="search">
        <van-search @focus="gotopage('/search')" readonly placeholder="请输入搜索关键词" />
      </div>
      <div class="swiper mt10">
        <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
          <van-swipe-item v-for="(item,index) in hbanners" :key="index">
              <van-image @click="gotopage('/detail/'+item._id+'?title='+item.title)" class="himg" :src="item.imgs[0].url.replace(/public/,baseURL)"></van-image>
          </van-swipe-item>
        </van-swipe>
      </div>
      <div class="navs">
        <van-tabs @change="changeType" v-model="type" color="#ee0a24" title-active-color="#ee0a24" sticky>
            <van-tab title="最热面试" name="1">
                <LoadMore :refreshfunc="refreshdata" :loaddata="loaddata">
                  <HList :list="hlist"  :type="type"  ></HList>
                </LoadMore>

            </van-tab>
            <van-tab title="最新面试" name="2">
                <LoadMore :refreshfunc="refreshdata" :loaddata="loaddata">
                  <HList :list="hlist" :type="type"></HList>
                </LoadMore>

            </van-tab>
          </van-tabs>
      </div>
  </div>
</template>

<script>
import { todogethomelist } from '@/api/api'
export default {
  data(){
    return {
      type:1,
      hlist:[],
      params:{
        page:1,
        pageSize:10,
      }
    }
  },
  methods:{
    async refreshdata(callback){
      this.params.page = 1;
      let res = await todogethomelist({
        ...this.params,
        type:this.type
      })
      if(res.code==200){
        this.hlist = res.result;
        callback()
      }
    },
    async loaddata(callback,callbackNoData){
      this.params.page+=1;  // 下一页数据
      let res = await todogethomelist({
        ...this.params,
        type:this.type
      })
      if(res.code==200){
          if(res.result.length>0){
            // 有数据
            this.hlist = this.hlist.concat(res.result)
            callback()  // 加载成功
          }else{
            // 数据见底了
            callbackNoData()
          }
      }
    },
    changeType(name){
       this.params.page = 1;
       this.getHomeListData()
    },
    async getHomeListData(){
      let res = await todogethomelist({
        ...this.params,
        type:this.type
      })
      if(res.code==200){
        this.hlist = res.result;
      }
    }
  },
  mounted(){
    this.getHomeBannerAsync()
    this.getHomeListData()
  }
}
</script>

<style lang="scss" scoped>
.home{
  width:100%;
  min-height:100%;
  .swiper{
    height:230px;
    width:100%;
    .my-swipe{
      height:230px;
      width:100%;
    }
    .himg{
      height:230px;
      width:100%;
    }
  }
}
</style>
